<template>
    <div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>会议类型</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div class="equipment-right-select"
                 @click="meetingTypePropShow = true">
                <span>{{addData.meetingType?addData.meetingType:'请选择'}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>会议时间</label>
                <i class="iconfont icon-required"></i>
            </div>
            <group>
                <datetime v-model="addData.meetingDate"
                          placeholder="请选择"
                          format="YYYY-MM-DD HH:mm"></datetime>
            </group>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>会议名称</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <textarea v-model="addData.meetingName"></textarea>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>会议地点</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <input type="text"
                       placeholder="请输入"
                       v-model="addData.meetingPosition">
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>主持人</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div class="equipment-right-select"
                 @click="fenBaoUserShow = true">
                <span>{{addData.meetingHoster?addData.meetingHoster:'请选择'}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>参会人员</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div class="equipment-right-select"
                 @click="fenBaoUserShow1 = true">
                <span>{{addData.meetingPerson?addData.meetingPerson:'请选择'}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>会议应到人数</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <p>{{addData.personCount}}</p>
            </div>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>会议议程</label>
            </div>
            <div>
                <textarea placeholder="请输入"
                          v-model="addData.mettingAgenda"></textarea>
            </div>
        </div>
        <div class="btns">
            <!-- <button>保存</button> -->
            <button class="green width200"
                    @click="submit">提交</button>
        </div>
        <myMenu></myMenu>
        <meetingTypeProp :selectMeetingType="selectMeetingType"
                         :meetingTypePropShow="meetingTypePropShow"></meetingTypeProp>
        <fenBaoUserProp :single="true"
                        :fenBaoUserShow="fenBaoUserShow"
                        :selectFenBaoUser="selectFenBaoUser"></fenBaoUserProp>
        <fenBaoUserProp :fenBaoUserShow="fenBaoUserShow1"
                        :selectFenBaoUser="selectFenBaoUser1"></fenBaoUserProp>
    </div>
</template>
<script>
import formatDate from '@/utils/formatDate'
import meetingTypeProp from '@/commonComponents/meetingTypeProp'
import fenBaoUserProp from '@/commonComponents/fenBaoUserProp'
import myMenu from '@/commonComponents/menu'
let getMonthWeek = function (a, b, c) {
    let date = new Date(a, parseInt(b) - 1, c)
    let w = date.getDay()
    let d = date.getDate()
    if (w == 0) {
        w = 7
    }
    var config = {
        getMonth: date.getMonth() + 1,
        getYear: date.getFullYear(),
        getWeek: Math.ceil((d + 6 - w) / 7)
    }
    return config
}
export default {
    name: 'addMeetingNotice',
    components: {
        meetingTypeProp,
        fenBaoUserProp,
        myMenu
    },
    data () {
        return {
            userInfo: {},
            unfoldMeasure: false,
            meetingTypePropShow: false,
            fenBaoUserShow: false,
            fenBaoUserShow1: false,
            addData: {
                meetingType: '', // 会议类型
                meetingDate: '', // 会议时间
                meetingName: '', // 会议名称
                meetingPosition: '', // 会议地点
                meetingHoster: '', // 主持人
                meetingPerson: '', // 参会人员
                meetingPersonID: '', // 参会人员Id
                personCount: '', // 会议应到人数
                mettingAgenda: '' // 会议议程
            }
        }
    },
    computed: {
        meetingName: function () {
            let name = ''
            if (this.addData.meetingDate && this.addData.meetingType) {
                let year = this.addData.meetingDate.split(' ')[0].split('-')[0]
                let month = this.addData.meetingDate.split(' ')[0].split('-')[1]
                let day = this.addData.meetingDate.split(' ')[0].split('-')[2]
                let getMonthWeekConfig = getMonthWeek(year, month, day)
                switch (this.addData.meetingType) {
                    case '周例会':
                        name = `${this.userInfo.deptname}${month}月第${getMonthWeekConfig.getWeek}周周例会`
                        break
                    case '月度例会':
                        name = `${this.userInfo.deptname}${month}月月度例会`
                        break
                    case '专题例会':
                        name = `${this.userInfo.deptname}${month}月专题例会`
                        break
                    case '安委会例会':
                        name = `${this.userInfo.deptname}${year}年${month}月${day}日安委会例会`
                        break
                    case '年度安全专题会':
                        name = `${this.userInfo.deptname}${year}年度专题例会`
                        break
                    default:
                        name = `${this.userInfo.deptname}${month}月安全例会`
                        break
                }
            }
            return name
        }
    },
    watch: {
        meetingName (val) {
            this.addData.meetingName = val
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.userInfo)
        let newDate = new Date()
        let hours = newDate.getHours() >= 10 ? newDate.getHours() : `0${newDate.getHours()}`
        let minutes = newDate.getMinutes() >= 10 ? newDate.getMinutes() : `0${newDate.getMinutes()}`
        this.addData.meetingDate = `${formatDate()} ${hours}:${minutes}`
    },
    methods: {
        selectMeetingType (item) {
            this.meetingTypePropShow = false
            this.addData.meetingType = item.TestType
        },
        selectFenBaoUser (item) {
            this.fenBaoUserShow = false
            this.addData.meetingHoster = item.Name
        },
        selectFenBaoUser1 (SendPersons, SendPersonsId) {
            this.fenBaoUserShow1 = false
            this.addData.meetingPerson = SendPersons
            this.addData.meetingPersonID = SendPersonsId
            this.addData.personCount = SendPersons.split(',').length
        },
        submit () {
            if (!this.addData.meetingType) {
                this.$vux.toast.text('请选择会议类型')
                return false
            } else if (!this.addData.meetingName) {
                this.$vux.toast.text('请输入会议名称')
                return false
            } else if (!this.addData.meetingPosition) {
                this.$vux.toast.text('请输入会议地点')
                return false
            } else if (!this.addData.meetingHoster) {
                this.$vux.toast.text('请选择主持人')
                return false
            } else if (!this.addData.meetingPerson) {
                this.$vux.toast.text('请选择参会人员')
                return false
            }
            let param = {
                'allowPaging': true,
                'business': 'InsertSafetyMeeting',
                'data': this.addData,
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': '',
                'method': 'new',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then((res) => {
                this.$vux.toast.text('提交成功')
                setTimeout(() => {
                    this.$router.go(-1)
                }, 500)
            })
        }
    }
}
</script>
